'''
Created on 2024年7月28日

@author: Administrator
'''
from util import TemperatureData as td
from datetime import datetime
import matplotlib.pyplot as plt


a = td('death_valley_2014.csv')
r = a.reader()

header_row = next(r)

for index,column_header in enumerate(header_row):
    print(index,column_header)

dates,highs,lows = [],[],[]
for row in r:
    current_date = datetime.strptime(row[0],'%Y-%m-%d')
    try:
        high = int(row[1])
        low = int(row[3])
    except ValueError:
        print(f"Miss data for {current_date}")
    else:
        dates.append(current_date)
        highs.append(high)
        lows.append(low)



plt.style.use('seaborn')
fig,ax = plt.subplots()
ax.plot(dates,highs,color='red',alpha=0.5)
ax.plot(dates,lows,color='blue',alpha=0.5)
ax.fill_between(dates,highs,lows,facecolor='blue',alpha=.1)


ax.set_title('Daily High and Low Temperatures,July 2021\nDeath Valley',fontsize=20)
ax.set_xlabel('',fontsize=16)
fig.autofmt_xdate()
ax.set_ylabel('Temperature (F)',fontsize=16)
ax.tick_params(labelsize=16)

plt.show()


